import md5 from 'js-md5'
export default function(obj){
    obj.prototype.md5 = md5;
    obj.prototype.confirm = function(data){//弹窗
      if(!data) data = {};
      if(!data.title) data.title='我是标题！';
      if(!data.msg) data.msg='我是内容主体！';
      if(!data.success) data.success=function a(){};
      if(!data.error) data.error=function a(){};
      var str = `
        <div class="confirm" style="position: fixed;z-index:10; width: 100%;height: 100%;top: 0;left: 0;background: rgba(0,0,0,.5);">
        <div style="max-width:28rem;min-width:24rem;position: absolute;left: 50%;top: 0;transform: translate(-50%,-50%);transform: -webkit-translate(-50%,-50%);background:#fff;border-radius:.6rem;">
          <h5 style="padding:0 1rem; font-size: 1.8rem;text-align: center;line-height: 3.5rem;">`+data.title+`</h5>
          <p style="padding:0 1rem;min-height:4rem; font-size: 1.4rem;text-align: center;line-height: 1.8rem;margin-bottom:1rem;">`+data.msg+`</p>
          <div>
            <button style="width:50%;font-size:1.7rem;border:0;border-top:1px solid #ccc; outline:none;color:#ffb000;background:none;float:left;line-height:3rem">确认</button>
            <button style="width:50%; font-size:1.7rem;border:0;border-left:1px solid #ccc;border-top:1px solid #ccc; outline:none;background:none;float:left;line-height:3rem">取消</button>
          </div>
        </div>
        </div>
      `;
      $('body').append(str);
      $('.confirm>div').animate({top:'30%'},300);
      $('.confirm button').click(function(){
        if($(this).index() == 0){
          data.success();
        }else{
          data.error();
        };
        $('.confirm').remove();
      });
    };
    obj.prototype.getData = function(obj){
      $.ajax({
        url:obj.url?obj.url:obj.$root.Url,
        type:obj.type?obj.type:'get',
        data:obj.json?obj.json:{},
        dataType:'json',
        success:obj.success?obj.success:function(){},
        error:obj.error?obj.error:function(e){
          console.log(obj.url,e);
        }
      })
    }
}
